import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/BasicInfomation',
    component: Layout,
    redirect: '/BasicInfomation',
    name: '/BasicInfomation',
    meta: {
      title: '基础',
      icon: 'nested'
    },
    children: [
      {
        path: 'CarManage',
        component: () => import('@/views/CarManage/CarManageIndex'),
        name: 'CarManage',
        meta: { title: '车辆管理' }
      },
      {
        path: 'ShipperManage',
        component: () => import('@/views/ShipperManage/ShipperManageIndex'),
        name: 'ShipperManage',
        meta: { title: '货主管理' }
      },
      {
        path: 'OutsourceManage',
        component: () => import('@/views/OutsourceManage/OutsourceManageIndex'),
        name: 'OutsourceManage',
        meta: { title: '外协单位管理' }
      },
      {
        path: 'OilCostManage',
        component: () => import('@/views/OilCostManage/OilCostManageIndex'),
        name: 'OilCostManage',
        meta: { title: '油费管理' }
      },
      {
        path: 'LineManage',
        component: () => import('@/views/LineManage/LineManageIndex'),
        name: 'LineManage',
        meta: { title: '线路管理' }
      }
    ]
  },
  {
    path: '/PersonnelManger',
    component: Layout,
    redirect: '/PersonnelManger',
    name: '/PersonnelManger',
    meta: {
      title: '人事',
      icon: 'nested'
    },
    children: [
      {
        path: 'PersonnelBoard',
        component: () => import('@/views/PersonnelBoard/PersonnelBoardIndex'),
        name: 'PersonnelBoard',
        meta: { title: '人事看板' }
      },
      {
        path: 'EmployeeRegistration',
        component: () => import('@/views/EmployeeRegistration/EmployeeRegistrationIndex'),
        name: 'EmployeeRegistration',
        meta: { title: '员工登记' }
      },
      {
        path: 'EntryTransaction',
        component: () => import('@/views/EntryTransaction/EntryTransactionIndex'),
        name: 'EntryTransaction',
        meta: { title: '入职办理' }
      },
      {
        path: 'DimissionTransaction',
        component: () => import('@/views/DimissionTransaction/DimissionTransactionIndex'),
        name: 'DimissionTransaction',
        meta: { title: '离职办理' }
      },
      {
        path: 'PositiveManage',
        component: () => import('@/views/PositiveManage/PositiveManageIndex'),
        name: 'PositiveManage',
        meta: { title: '转正管理' }
      }
    ]
  },
  {
    path: '/ContractManage',
    component: Layout,
    redirect: '/ContractManage',
    name: '/ContractManage',
    meta: {
      title: '合同',
      icon: 'nested'
    },
    children: [
      {
        path: 'OwnerContractManage',
        component: () => import('@/views/OwnerContractManage/OwnerContractManageIndex'),
        name: 'OwnerContractManage',
        meta: { title: '货主合同管理' }
      },
      {
        path: 'CarrierContractManage',
        component: () => import('@/views/CarrierContractManage/CarrierContractManageIndex'),
        name: 'CarrierContractManage',
        meta: { title: '承运合同管理' }
      },
      {
        path: 'GeneralContractManage',
        component: () => import('@/views/GeneralContractManage/GeneralContractManageIndex'),
        name: 'GeneralContractManage',
        meta: { title: '通用合同管理' }
      }
    ]
  },
  {
    path: '/BalanceManger',
    component: Layout,
    redirect: '/BalanceManger',
    name: '/BalanceManger',
    meta: {
      title: '结算',
      icon: 'nested'
    },
    children: [
      {
        path: 'ReceivableCostManage',
        component: () => import('@/views/ReceivableCostManage/ReceivableCostManageIndex'),
        name: 'ReceivableCostManage',
        meta: { title: '应收费用管理' }
      },
      {
        path: 'HandleCostManage',
        component: () => import('@/views/HandleCostManage/HandleCostManageIndex'),
        name: 'HandleCostManage',
        meta: { title: '应付费用管理' }
      },
      {
        path: 'IncomeInvoiceManage',
        component: () => import('@/views/IncomeInvoiceManage/IncomeInvoiceManageIndex'),
        name: 'IncomeInvoiceManage',
        meta: { title: '进项发票管理' }
      },
      {
        path: 'OutputInvoiceManage',
        component: () => import('@/views/OutputInvoiceManage/OutputInvoiceManageIndex'),
        name: 'OutputInvoiceManage',
        meta: { title: '销项发票管理' }
      }
    ]
  },
  {
    path: '/Materials',
    component: Layout,
    redirect: '/Materials',
    name: '/Materials',
    meta: {
      title: '物资',
      icon: 'nested'
    },
    children: [
      {
        path: 'MaterialsPurchasing',
        component: () => import('@/views/MaterialsPurchasing/MaterialsPurchasingIndex'),
        name: 'MaterialsPurchasing',
        meta: { title: '物资采购' }
      },
      {
        path: 'StockManage',
        component: () => import('@/views/StockManage/StockManageIndex'),
        name: 'StockManage',
        meta: { title: '入库管理' }
      },
      {
        path: 'MaterialReceive',
        component: () => import('@/views/MaterialReceive/MaterialReceiveIndex'),
        name: 'MaterialReceive',
        meta: { title: '物资领用' }
      },
      {
        path: 'MaterialStatistics',
        component: () => import('@/views/MaterialStatistics/MaterialStatisticsIndex'),
        name: 'MaterialStatistics',
        meta: { title: '物资统计' }
      },
      {
        path: 'RefundManage',
        component: () => import('@/views/RefundManage/RefundManageIndex'),
        name: 'RefundManage',
        meta: { title: '报销管理' }
      },
      {
        path: 'PaymentManage',
        component: () => import('@/views/PaymentManage/PaymentManageIndex'),
        name: 'PaymentManage',
        meta: { title: '付款管理' }
      }
    ]
  },
  {
    path: '/Safeguard',
    component: Layout,
    redirect: '/Safeguard',
    name: '/Safeguard',
    meta: {
      title: '维护',
      icon: 'nested'
    },
    children: [
      {
        path: 'MaintainRecord',
        component: () => import('@/views/MaintainRecord/MaintainRecordIndex'),
        name: 'MaintainRecord',
        meta: { title: '维修记录' }
      },
      {
        path: 'UpkeepRecord',
        component: () => import('@/views/UpkeepRecord/UpkeepRecordIndex'),
        name: 'UpkeepRecord',
        meta: { title: '保养记录' }
      },
      {
        path: 'BreakrulesRecord',
        component: () => import('@/views/BreakrulesRecord/BreakrulesRecordIndex'),
        name: 'BreakrulesRecord',
        meta: { title: '违章记录' }
      },
      {
        path: 'AccidentRecord',
        component: () => import('@/views/AccidentRecord/AccidentRecordIndex'),
        name: 'AccidentRecord',
        meta: { title: '事故记录' }
      },
      {
        path: 'TireuseRecord',
        component: () => import('@/views/TireuseRecord/TireuseRecordIndex'),
        name: 'TireuseRecord',
        meta: { title: '轮胎使用记录' }
      },
      {
        path: 'CostRecord',
        component: () => import('@/views/CostRecord/CostRecordIndex'),
        name: 'CostRecord',
        meta: { title: '费用记录' }
      }
    ]
  },
  {
    path: '/Track',
    component: Layout,
    redirect: '/Track',
    name: '/Track',
    meta: {
      title: '跟踪',
      icon: 'nested'
    },
    children: [
      {
        path: 'OwnerContractTrack',
        component: () => import('@/views/OwnerContractTrack/OwnerContractTrackIndex'),
        name: 'OwnerContractTrack',
        meta: { title: '货主合同跟踪' }
      },
      {
        path: 'CarrierContractTrack',
        component: () => import('@/views/CarrierContractTrack/CarrierContractTrackIndex'),
        name: 'CarrierContractTrack',
        meta: { title: '承运合同跟踪' }
      }
    ]
  },
  {
    path: '/Approval',
    component: Layout,
    redirect: '/Approval',
    name: '/Approval',
    meta: {
      title: '审批',
      icon: 'nested'
    },
    children: [
      {
        path: 'OwnerContractApproval',
        component: () => import('@/views/OwnerContractApproval/OwnerContractApprovalIndex'),
        name: 'OwnerContractApproval',
        meta: { title: '货主合同审批' }
      },
      {
        path: 'CarrierContractApproval',
        component: () => import('@/views/CarrierContractApproval/CarrierContractApprovalIndex'),
        name: 'CarrierContractApproval',
        meta: { title: '承运合同审批' }
      },
      {
        path: 'GeneralContractApproval',
        component: () => import('@/views/GeneralContractApproval/GeneralContractApprovalIndex'),
        name: 'GeneralContractApproval',
        meta: { title: '通用合同审批' }
      },
      {
        path: 'MaterialsPurchasingApproval',
        component: () => import('@/views/MaterialsPurchasingApproval/MaterialsPurchasingApprovalIndex'),
        name: 'MaterialsPurchasingApproval',
        meta: { title: '物资采购审批' }
      },
      {
        path: 'MaterialReceiveApproval',
        component: () => import('@/views/MaterialReceiveApproval/MaterialReceiveApprovalIndex'),
        name: 'MaterialReceiveApproval',
        meta: { title: '物资领用审批' }
      },
      {
        path: 'RefundApproval',
        component: () => import('@/views/RefundApproval/RefundApprovalIndex'),
        name: 'RefundApproval',
        meta: { title: '报销审批' }
      },
      {
        path: 'PaymentApproval',
        component: () => import('@/views/PaymentApproval/PaymentApprovalIndex'),
        name: 'PaymentApproval',
        meta: { title: '付款审批' }
      },
      {
        path: 'EntryApproval',
        component: () => import('@/views/EntryApproval/EntryApprovalIndex'),
        name: 'EntryApproval',
        meta: { title: '入职审批' }
      },
      {
        path: 'DimissionApproval',
        component: () => import('@/views/DimissionApproval/DimissionApprovalIndex'),
        name: 'DimissionApproval',
        meta: { title: '离职审批' }
      },
      {
        path: 'PositiveApproval',
        component: () => import('@/views/PositiveApproval/PositiveApprovalIndex'),
        name: 'PositiveApproval',
        meta: { title: '转正审批' }
      }
    ]
  },
  {
    path: '/SystemManger',
    component: Layout,
    redirect: '/SystemManger',
    name: '/SystemManger',
    meta: {
      title: '设置',
      icon: 'nested'
    },
    children: [
      {
        path: 'BasicInfomationSettings',
        component: () => import('@/views/BasicInfomationSettings/BasicInfomationSettingsIndex'),
        name: 'BasicInfomationSettings',
        meta: { title: '基础信息设置' }
      },
      {
        path: 'OperatorManage',
        component: () => import('@/views/OperatorManage/OperatorManageIndex'),
        name: 'OperatorManage',
        meta: { title: '操作员管理' }
      },
      {
        path: 'RoleManage',
        component: () => import('@/views/RoleManage/RoleManageIndex'), name: 'RoleManage',
        meta: { title: '角色管理' }
      },
      {
        path: 'DepartmentManage',
        component: () => import('@/views/DepartmentManage/DepartmentManageIndex'),
        name: 'DepartmentManage',
        meta: { title: '部门管理' }
      },
      {
        path: 'PositionManage',
        component: () => import('@/views/PositionManage/PositionManageIndex'),
        name: 'PositionManage',
        meta: { title: '职位管理' }
      }
    ]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
